#include "geminai_frig.h"

#define frig_pwrctl_delay(time)		(frig_ctr_para.timer >= time)

static frig_ctr frig_ctr_para;//制冷控制参数
static defrost_ctr defrost_ctr_para;//除霜控制参数

static uint8_t frig_first_pwron = 1;//系统第一次上电标志
static uint8_t defrost_frist_conf = 1;//首次除霜
static uint8_t compressor_wkstat = 0;//压缩机工作状态

static uint32_t fans_protect_run_tim_t=0;//风机高温保护运行计时时间
static uint8_t fans_wkstat =0;//风机工作状态

static void set_fan_run_tim(void);
static void set_comp_run_tim(void);
static void set_comp_act_cnt(uint8_t stat);
static void set_fan_act_cnt(uint8_t stat);
TimerHandle_t xTimer_frig_peripheral;
TimerHandle_t xTimer_frig_ctrl_1hz;
TimerHandle_t xTimer_frig_ctrl_10hz;

//@brief 获取压缩机工作状态
uint8_t get_compressor_status(void){
	return compressor_wkstat;
}

//@brief 压缩机状态置为工作状态(开启)
void compressor_set_work(void){
	compressor_wkstat = 1;
}

// @brief 压缩机状态置为不工作状态(关闭)
void compressor_reset_work(void){
	compressor_wkstat = 0;
}

//@brief 获取风机状态
uint8_t get_fans_status(void){
	return fans_wkstat;
}

// @brief 风机状态置为工作状态(开启)
void fans_set_work(void){
	 fans_wkstat = 1;
}

// @brief 风机状态置为不工作状态(关闭)
void fans_reset_work(void){
	 fans_wkstat = 0;
}

//@brief 获取系统开关状态
static uint8_t frig_sys_sw_get(void){
	return frig_sys_switch;
}

//@brief 获取累计除霜时间
uint16_t dafrost_exec_get(void){
	return defrost_ctr_para.defrost_work_time;
}


/**
 * @brief  发送上报事件到阿里云
 * 
 * @param event 需要设置的主动上报事件项
 */
void frig_event_set(event_stat event)
{
    switch(event)
    {
        case EVENT_LED_SW:
		attribute_send_event |= PARA_LIGHT_SWITCH;
        break;
        case EVENT_FRIG_SW:
		attribute_send_event |= PARA_COOL_SWITCH;
		attribute_send_event |= PARA_EVAPORATOR_STATUS;
		attribute_send_event |= PARA_COMPRESSOR_STATUS;
        break;
        case EVENT_FRIG_NORMAL_STATE:
		attribute_send_event |= PARA_COLD_NORMAL_STATE;
        break;
        case EVENT_FRIG_DEFROST_STATE:
		attribute_send_event |= PARA_COLD_DEFROST_STATE;
        break;
        case EVENT_FRIG_FORCED_STATE:
		attribute_send_event |= PARA_COLD_FROCE_STATE;
        break;
		case EVENT_FRIG_RUN_MODE:
		attribute_send_event |= PARA_FRIG_RUN_MODE;
        break;
		case EVENT_OVERTEMP_ALARM:
		attribute_send_event |= PARA_OVERTEMP_ALARM;
        break;
		case EVENT_LOWTEMP_ALARM:
		attribute_send_event |= PARA_LOWTEMP_ALARM;
        break;
        default:
        break;
    }
}

/**
 * @brief  制冷控制状态设置
 * 
 * @param _state 控制状态设置
 * @param tim    时间设置
 */
void frig_set_stat(uint8_t _state, uint32_t tim)
{
	frig_ctr_para.state = _state;
	frig_ctr_para.timer = tim;
}

/**
 * @brief  制冷控制状态获取
 */
int aiot_get_frig_stat(void)
{
    return frig_ctr_para.state;
}

/**
 * @brief 控制板1S控制任务(空闲模式--FRIG_STAT_IDLE 错误模式--FRIG_STAT_ERROR_MODE 正常运行模式--FRIG_STAT_NORMAL_MODE 化霜模式--FRIG_STAT_DEFROST_MODE)
 * 
 */
void frig_ctl_1hz(TimerHandle_t xTimer)
{
	static uint8_t defrost_time=0;
	float temp_offset = 1.5;

	if(temp_ctl_para.device_lock || (!frig_sys_switch && frig_ctr_para.state == FRIG_STAT_ERR_MODE))
		return;
	frig_ctr_para.timer++;
	switch(frig_ctr_para.state)
	{
		case FRIG_STAT_IDLE:
			//if(frig_ctr_para.timer == 1)
			{				
				alarm_stat &=~ ALARM_DEFORST;						//取消df除霜
				alarm_stat &=~ ALARM_FORCED_COOL;					//取消CC强制制冷
				alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;           //最小停机时间
			}
			if(temp_ctl_para.forced_cooling)
			{
				frig_set_stat(FRIG_STAT_FORCE_MODE, 0);
				break;
			}
			//memset(&frig_ctr_para, 0, sizeof(frig_ctr_para));
			
			//第一次上电或系统开关由断开到闭合都是先让压缩机工作
			/*if((sys_temp.temp_per_min < TEMP_ERR_LOWER) || (sys_temp.temp_per_min > TEMP_ERR_UPPER))//温度异常或传感器数据异常
			{
				//frig_set_stat(FRIG_STAT_ERR_MODE, 15*60);				
				frig_set_stat(FRIG_STAT_ERR_MODE, 10*60);
				frig_ctr_para.err_mode_toggle = SET;//进入异常模式顺序:先停机,后工作
			}
			else*/
			{
				if(frig_first_pwron)
					frig_set_stat(FRIG_STAT_NORMAL_MODE, 0);//首次上电状态,从零开始计时运行一段时间(压机延时保护时间)
				else{
					frig_set_stat(FRIG_STAT_NORMAL_MODE, frig_ctr_para.timer);
					//printf("start frig normal mode = %ld\n",frig_ctr_para.timer);	
				}
			}
			break;

		case FRIG_STAT_ERR_MODE:
			if((sys_temp.temp_per_min >= TEMP_ERR_LOWER) && (sys_temp.temp_per_min <= TEMP_ERR_UPPER))
			{
				if( get_compressor_status() )
					frig_set_stat(FRIG_STAT_NORMAL_MODE, temp_ctl_para.delay_tim*60);//错误模式下在工作状态,恢复正常模式可直接工作
				else	
					frig_set_stat(FRIG_STAT_NORMAL_MODE, frig_ctr_para.timer);//错误模式下在停机状态,恢复正常模式要等保护时间到才工作
				break;
			}
			//开10min停15min
			if(!frig_ctr_para.err_mode_toggle)
			{
				if(frig_pwrctl_delay(15*60))//15*60
				{
					frig_ctr_para.err_mode_toggle = SET;
					frig_set_stat(FRIG_STAT_ERR_MODE, 0);//清计时器
				}
				else					
					compressor_reset_work();
			}
			else
			{
				if(frig_pwrctl_delay(10*60))//10*60
				{
					frig_ctr_para.err_mode_toggle = RESET;
					frig_set_stat(FRIG_STAT_ERR_MODE, 0);//清计时器
				}
				else					
					compressor_set_work();
			}
			break;

		case FRIG_STAT_NORMAL_MODE:
			if((sys_temp.temp_per_min < TEMP_ERR_LOWER) || (sys_temp.temp_per_min > TEMP_ERR_UPPER))
			{
				alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;
                /*
				if( is_compressor_work() )
					frig_set_stat(FRIG_STAT_ERR_MODE, 15*60);//正常模式下在工作状态,进入错误模式可直接工作
				else
				{
					//if(frig_ctr_para.timer >= temp_ctl_para.delay_tim*60)
					if(frig_pwrctl_delay(temp_ctl_para.delay_tim*60))//5*60
						frig_set_stat(FRIG_STAT_ERR_MODE, 15*60);//正常模式下在停机状态,进入错误模式要等保护时间到才工作
					else
						frig_set_stat(FRIG_STAT_ERR_MODE, (10*60+frig_ctr_para.timer) );//正常模式下在停机状态,进入错误模式要等保护时间到才工作
				}
				
				frig_ctr_para.err_mode_toggle = RESET;//进入异常模式顺序:先工作,后停
                */
				// if(frig_first_pwron)
					// compressor_set_work();
				
				frig_set_stat(FRIG_STAT_ERR_MODE,0);
				frig_ctr_para.err_mode_toggle = RESET;//进入异常模式顺序:先停机,后工作
				break;
			}
			
			if(frig_ctr_para.timer == 1)
			{
				temp_ctl_para.forced_cooling = 0;
				// frig_event_set(EVENT_FRIG_NORMAL_STATE);//发送正常制冷模式事件
				alarm_stat &=~ ALARM_DEFORST;							//取消df除霜
				alarm_stat &=~ ALARM_FORCED_COOL;					//取消CC强制制冷
			}
			if(frig_first_pwron)//首次上电 [5~8]也工作(工作3min)
			{
				compressor_set_work();
				if(frig_pwrctl_delay(90))
				{
					frig_first_pwron = 0;
					frig_set_stat(FRIG_STAT_NORMAL_MODE, temp_ctl_para.delay_tim*60);//清计时器
				}
			}
			else
			{
				if(sys_temp.real_temp + temp_offset < temp_ctl_para.temp_des)//温度很低,停止工作 5
				//if(sys_temp.temp_per_min + temp_offset < temp_ctl_para.temp_des)//改为用平均min温度来判断 拉低到4度
				{
					alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;	//取消最小停机时间压机标志闪烁
					compressor_reset_work();
					frig_set_stat(FRIG_STAT_NORMAL_MODE, 0);//清计时器
				}
				else
				{
					if(sys_temp.real_temp + temp_offset > (temp_ctl_para.temp_des+temp_ctl_para.temp_diff))//启动压缩机 8
					//if(sys_temp.temp_per_min + temp_offset > (temp_ctl_para.temp_des+temp_ctl_para.temp_diff))//启动压缩机 8 7
					{
						if(frig_pwrctl_delay(temp_ctl_para.delay_tim*60))//5*60
						{
							alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;	//取消最小停机时间压机标志闪烁
							compressor_set_work();
							//frig_set_stat(FRIG_STAT_NORMAL_MODE, 0);//清计时器
						}
						else{
							alarm_stat |= ALARM_IS_COMPRESSOR_DELAY;	//显示最小停机时间压机标志闪烁
						}
					}
				}
			}
			
			break;

		case FRIG_STAT_DEFROST_MODE://化霜模式
			if(frig_ctr_para.timer == 1)
			{				
				defrost_ctr_para.comp_wk_tim_total = 0;
				temp_ctl_para.forced_cooling = 0;
                defrost_frist_conf=0;
				frig_event_set(EVENT_FRIG_DEFROST_STATE);//发送除霜模式事件
				alarm_stat |= ALARM_DEFORST;							//显示df除霜
				alarm_stat &=~ ALARM_FORCED_COOL;					//取消CC强制制冷
				alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;	//取消最小停机时间压机标志位闪烁
			}
			if(defrost_time++ == 60)
			{
				defrost_time = 0;
				defrost_ctr_para.defrost_work_time++;
			}
			alarm_stat &=~ ALARM_OVERTEMP;							//取消高温报警显示
			compressor_reset_work();
			
			if(frig_pwrctl_delay(defrost_ctr_para.defrost_tim))
			{
				if(overtemp_time < temp_ctl_para.defrost_shielding_time)	//除霜后屏蔽时间
				{
					overtemp_time = temp_ctl_para.defrost_shielding_time;
				}
				frig_event_set(EVENT_FRIG_NORMAL_STATE);//发送正常制冷模式事件
				frig_set_stat(FRIG_STAT_IDLE, frig_ctr_para.timer);//清计时器
			}
			break;

		case FRIG_STAT_FORCE_MODE://强制制冷模式
			if(frig_ctr_para.timer == 1)
			{
				temp_ctl_para.forced_cooling = 1;
				frig_event_set(EVENT_FRIG_FORCED_STATE);//发送强制制冷模式事件
				alarm_stat |= ALARM_FORCED_COOL;					//显示CC强制制冷
				alarm_stat &=~ ALARM_DEFORST;							//取消df除霜
				alarm_stat &=~ ALARM_IS_COMPRESSOR_DELAY;	//取消最小停机时间压机标志位闪烁
			}
			if(sys_temp.real_temp + temp_offset > 1)//启动压缩机 
			{
					compressor_set_work();
			}
			else
			{
				temp_ctl_para.temp_des = 3;
				temp_ctl_para.forced_cooling = 0;
				frig_event_set(EVENT_FRIG_NORMAL_STATE);//发送正常制冷模式事件
				frig_set_stat(FRIG_STAT_IDLE, 0);//清计时器
			}

			if(frig_pwrctl_delay(60*2*60) )//2h
			{
				temp_ctl_para.temp_des = 3;
				temp_ctl_para.forced_cooling = 0;
				frig_event_set(EVENT_FRIG_NORMAL_STATE);//发送正常制冷模式事件
				frig_set_stat(FRIG_STAT_IDLE, frig_ctr_para.timer);//清计时器
			}
			break;
	}


	//----------------化霜逻辑判定----------------
	switch(frig_ctr_para.state)
	{
		case FRIG_STAT_NORMAL_MODE://温度探头正常
			if(defrost_frist_conf)//首次除霜
			{
				defrost_ctr_para.defrost_trust_tim = 20*3600;//20h
				defrost_ctr_para.defrost_tim = temp_ctl_para.defrost_time*60;//20min
			}
			else
			{
				defrost_ctr_para.defrost_trust_tim = temp_ctl_para.defrost_cycle*60;//4h
				defrost_ctr_para.defrost_tim = temp_ctl_para.defrost_time*60;//20min
			}

			defrost_ctr_para.comp_wk_tim_total++;
			if(defrost_ctr_para.comp_wk_tim_total >= defrost_ctr_para.defrost_trust_tim)
			{
				defrost_ctr_para.comp_wk_tim_total = 0;
				frig_set_stat(FRIG_STAT_DEFROST_MODE, 0);//除霜
			}
				
			break;
	}

}

/**
 * @brief 控制功能(根据系统开关) 统计相应设备的运行时间和动作次数
 * 
 */
void frig_ctl_10hz(TimerHandle_t xTimer)
{
	static uint8_t sw_toggle = 0;//系统开关改变后执行的动作只执行一次
	static uint8_t comp_toggle = 0;//压缩机开关状态改变后执行的动作只执行一次

	static uint8_t fans_toggle = 0;//风机开关状态改变后执行的动作只执行一次
	static uint8_t fans_protect_toggle = 0;//风机开关状态改变后执行的动作只执行一次
	static uint16_t fans_stop_count = 0;//风机停机时间

	if( frig_sys_sw_get() )//系统开关打开
	{
		if(0 == sw_toggle && !temp_ctl_para.device_lock)
		{
			fans_set_work();
			if(frig_ctr_para.state != FRIG_STAT_ERR_MODE)				
				frig_set_stat(FRIG_STAT_IDLE, frig_ctr_para.timer);
		}
		sw_toggle = 1;
		
		
		if(frig_ctr_para.state == FRIG_STAT_DEFROST_MODE)
			fans_set_work();
		
		if(fans_protect_run_tim_t > temp_ctl_para.overtemp_fans_protect_time && sys_temp.temp_per_min > temp_ctl_para.overtemp_fans_protect_temp )//风机高温保护
		{		
			fans_reset_work();
			fans_protect_toggle = 0;
		}
		else
		{
			if(fans_protect_toggle == 0)
			{
				fans_protect_run_tim_t = 0;
				fans_set_work();
			}
			fans_protect_toggle = 1;
			
			if(fans_stop_count++ > 10)	//风机关闭时间大于5min则强制开启风机
			{
				if(RLY_FANS_GET)//检测风机继电器状态
				{
					fans_stop_count = 0;
				}
				else
				{
					if(fans_stop_count > 3000)
					{
						fans_set_work();
						RLY_FANS_ON;//开启风机
						fans_stop_count = 0;
					}
				}
			}			
		}
		
		if(get_fans_status())
		{
			if(0 == fans_toggle)
			{
				fans_set_work();//设置风扇工作状态
				RLY_FANS_ON;//开启风机
				fans_toggle = 1;
			}
		}
		else
		{
			if(1 == fans_toggle)
			{
				fans_reset_work();//设置风扇工作状态
				RLY_FANS_OFF;//关闭风机
				fans_toggle = 0;
			}
		}
	

		if(get_compressor_status() && !temp_ctl_para.device_lock)
		{
			if(0 == comp_toggle){
				RLY_COMP_ON;
			}
			comp_toggle = 1;
		}
		else
		{
			
			if(1 == comp_toggle){
				RLY_COMP_OFF;
			}
			comp_toggle = 0;
		}
	}
	else//系统开关关闭
	{
		if(1 == sw_toggle)
		{
			alarm_stat = 0;
			if(get_compressor_status() && (frig_ctr_para.state != FRIG_STAT_ERR_MODE) )//获取压机状态，关机后重新计时  异常模式不需要重新计时
			{							
				frig_set_stat(FRIG_STAT_IDLE, 0);
			}
			compressor_reset_work();
			fans_reset_work();
			RLY_FANS_OFF;//风扇关闭
			RLY_COMP_OFF;//压机关闭
		}
		sw_toggle = 0;
		comp_toggle = 0;
		fans_toggle = 0;
	}
	
	//累计风机运行时间
	if(get_fans_status())
		set_fan_run_tim();
	
	//累计压机运行时间
	if(comp_toggle)
		set_comp_run_tim();
	

	set_fan_act_cnt(sw_toggle);//累计风机继电器动作次数
	set_comp_act_cnt(comp_toggle);//累计压机继电器动作次数
}

//@brief 统计压缩机工作时间
static void set_comp_run_tim(void)
{
	static uint32_t run_tim_t = 0;

	run_tim_t++;//函数10hz调用一次,也即0.1s累加一次	
	
	if(run_tim_t>=0xFFFFFFFF)
	{
		run_tim_t=0;
	}

	devices_tim_cnt.t_compressor = run_tim_t/600;//计量单位为1分钟
}

//@brief 统计蒸发风机工作时间
static void set_fan_run_tim(void)
{
	static uint16_t run_tim_t = 0;

	run_tim_t++;//函数10hz调用一次,也即0.1s累加一次	
	
	if(run_tim_t == 600)
	{
		fans_protect_run_tim_t++;
		devices_tim_cnt.t_vaporizerfan++;
		run_tim_t = 0;
		if(fans_protect_run_tim_t == 0xFFFFFFFF)
			fans_protect_run_tim_t = 0;
		if(devices_tim_cnt.t_vaporizerfan == 0xFFFFFFFF)
			devices_tim_cnt.t_vaporizerfan = 0;
	}
}

/**
 * @brief 设置压缩机动作次数(压机控制状态改变,累计一次压机继电器动作)
 * 
 * @param stat 压缩机控制状态
 */
static void set_comp_act_cnt(uint8_t stat)
{
	static uint8_t stat_t = 0;

	if(stat_t != stat)//压机控制状态改变,累计一次压机继电器动作
		devices_tim_cnt.c_compressorrelay++;
	stat_t = stat;
}

/**
 * @brief 设置蒸发风机动作次数(风机控制状态改变,累计一次风机继电器动作)
 * 
 * @param stat 风机控制状态
 */
static void set_fan_act_cnt(uint8_t stat)
{
	static uint8_t stat_t = 0;
	
	if(stat_t != stat)//风机控制状态改变,累计一次风机继电器动作
		devices_tim_cnt.c_vaporizerrelay++;
	stat_t = stat;
}

void peripheral_ctl_2hz(TimerHandle_t xTimer)
{
	static uint8_t alarm_stat_temp=0;
	uint8_t Bji=0;
	static uint16_t alarm_cnt=0;
	float TEMP=sys_temp.real_temp+1.5;
	static uint8_t ledchange = 0;

	//锁机
	if(temp_ctl_para.device_lock)
	{
		digital_display(0xf7,0);
		led_pwm_set(0);
		return;
	}
	
// 定义先前的 LED 状态
static bool previous_led_status = true;
static uint8_t led_pwm_t = 100;

if(led_pwm_t != temp_ctl_para.led_pwm && led_status == 1)
{
	led_pwm_t = temp_ctl_para.led_pwm;
	led_pwm_set(led_pwm_t);
}


if (led_status != previous_led_status && temp_ctl_para.light_ctrl == 1) // 检查状态是否变化
{
    previous_led_status = led_status; // 更新状态
	ledchange = 2;
    if (led_status) // 如果 LED 状态为真
    {
		if(temp_ctl_para.led_pwm == 0)
		{
			frig_event_set(PARA_LED_PWM);
			temp_ctl_para.led_pwm = 100;
		}
        led_pwm_set(temp_ctl_para.led_pwm);
    }
    else // 如果 LED 状态为假
    {
        led_pwm_set(0); // PWM 设为 0
    }
}	
	static uint8_t toggle_counter_lte = 0;

	// 4g
	if (check_result.lte) {
		Bji |= CH_SIGNAL;
	} else {
		toggle_counter_lte++;
		if (toggle_counter_lte % 3) {
			Bji ^= CH_SIGNAL; // 每两次翻转一次
		}
	}

	static uint8_t toggle_counter_comp = 0;
	//压缩机延时保护
	if ((ALARM_IS_COMPRESSOR_DELAY & alarm_stat) && frig_sys_sw_get()) {
		// 使用相同的计数器逻辑
		toggle_counter_comp++;
		if (toggle_counter_comp % 3) {
			Bji ^= CH_FRIGE; // 每两次翻转一次
		}
	} else {
		if (RLY_COMP_GET)
			Bji |= CH_FRIGE;
		else	
			Bji &=~ CH_FRIGE;
	}

	if(RLY_FANS_GET)
		Bji |= CH_FAN;
	else	
		Bji &=~ CH_FAN;
	
	//制冷开关关闭
	if(!frig_sys_sw_get())
	{
		if(ledchange){
			TEMP = (led_status != 0) ? 0xf6 : 0xf5;
			ledchange--;
			digital_display(TEMP,Bji);
		}
		else
			digital_display(0xf9,Bji);
		return;
	}

	if(alarm_stat & ALARM_DEFORST)
	{
		Bji |= CH_DEFROST;
	}
	else
	{
		Bji &=~ CH_DEFROST;
	}
	
	if(ledchange){
		TEMP = (led_status != 0) ? 0xf6 : 0xf5;
		ledchange--;
		digital_display(TEMP,Bji);
		return;
	}


static uint8_t entry_counter = 0; // 计数器，用于跟踪进入次数

//故障灯显示
if(alarm_stat != 0)
{
    entry_counter++; // 每次进入时递增计数器

    if (entry_counter % 2 == 0) // 只有在计数器为偶数时才执行逻辑
    {
	if(alarm_cnt == 0)
	{
		alarm_stat_temp = alarm_stat;
		uint8_t aa=1; 
		while(aa < 127)
		{
			if(aa & alarm_stat_temp) {alarm_cnt++;}
			aa = aa << 1;
		}						
		if(alarm_stat_temp & ALARM_FORCED_COOL || alarm_stat_temp & ALARM_OVERTEMP || alarm_stat_temp & ALARM_LOWTEMP)
			alarm_cnt++;
	}
	
	if(alarm_stat_temp & ALARM_OVERTEMP)   	{TEMP = 0xfb; alarm_stat_temp&=~ALARM_OVERTEMP;   }//高温报警
	else if(alarm_stat_temp & ALARM_LOWTEMP)     	{TEMP = 0xfa; alarm_stat_temp&=~ALARM_LOWTEMP;    }//低温报警
	else if(alarm_stat_temp & ALARM_DOOR) 	    	{TEMP = 0xfc; alarm_stat_temp&=~ALARM_DOOR;       }//开门超时报警
	else if(alarm_stat_temp & ALARM_DEFORST)	    {TEMP = 0xfd; alarm_stat_temp&=~ALARM_DEFORST;    }//除霜模式
	else if(alarm_stat_temp & ALARM_FORCED_COOL) 	{TEMP = 0xf8; alarm_stat_temp&=~ALARM_FORCED_COOL;}//强制制冷模式
	else if(alarm_stat_temp & ALARM_NTC1_ERROR)		{TEMP = 0xfe; alarm_stat_temp&=~ALARM_NTC1_ERROR; }//ntc1异常
	else if(alarm_stat_temp & ALARM_NTC2_ERROR)		{TEMP = 0xff; alarm_stat_temp&=~ALARM_NTC2_ERROR; }//ntc2异常
						
	if(alarm_cnt > 0) {alarm_cnt--;}
	digital_display(TEMP,Bji);
	}
	return;

}


	digital_display(TEMP,Bji);

}

#define TIMER_PERIOD01 pdMS_TO_TICKS(100) // 定时器间隔为0.1秒
#define TIMER_PERIOD02 pdMS_TO_TICKS(500) // 定时器间隔为0.5秒
#define TIMER_PERIOD10 pdMS_TO_TICKS(1000) // 定时器间隔为1秒
void frig_task(void)
{
	xTimer_frig_peripheral = xTimerCreate("TimerPeripheral", TIMER_PERIOD02, pdTRUE, (void *)0, peripheral_ctl_2hz);
	xTimerStart(xTimer_frig_peripheral, 0);
	xTimer_frig_ctrl_1hz = xTimerCreate("TimeCrtl1hz", TIMER_PERIOD10, pdTRUE, (void *)0, frig_ctl_1hz);
	xTimerStart(xTimer_frig_ctrl_1hz, 0);
	xTimer_frig_ctrl_10hz = xTimerCreate("TimeCrtl10hz", TIMER_PERIOD01, pdTRUE, (void *)0, frig_ctl_10hz);
	xTimerStart(xTimer_frig_ctrl_10hz, 0);	
}